function parsePath(path) {
    const segments = path.split('.');
    return function(obj) {
        for (let i = 0; i < segments.length; i++) {
            if (!obj) return undefined;
            obj = obj[segments[i]];
        }

        return obj;
    }
}

const get = parsePath('x.y.z');
console.log(get({x:{y:{z:42}}}));
console.log(get({x:{y:{z:{ name: 'Tony Stark' }}}}));
console.log(get({x:{yy:{z:{ name: 'Tony Stark' }}}}));
